﻿-- Function: tesoreria.mestcta_insert_trigger()

-- DROP FUNCTION tesoreria.mestcta_insert_trigger();

CREATE OR REPLACE FUNCTION tesoreria.mestcta_insert_trigger()
  RETURNS trigger AS
$BODY$
begin

	if new.cperanio = '1996'    then insert into tesoreria.mestcta_a1996 values (new.*);
	elsif new.cperanio = '1997' then insert into tesoreria.mestcta_a1997 values (new.*);
	elsif new.cperanio = '1998' then insert into tesoreria.mestcta_a1998 values (new.*);
	elsif new.cperanio = '1999' then insert into tesoreria.mestcta_a1999 values (new.*);
	elsif new.cperanio = '2000' then insert into tesoreria.mestcta_a2000 values (new.*);
	elsif new.cperanio = '2001' then insert into tesoreria.mestcta_a2001 values (new.*);
	elsif new.cperanio = '2002' then insert into tesoreria.mestcta_a2002 values (new.*);
	elsif new.cperanio = '2003' then insert into tesoreria.mestcta_a2003 values (new.*);
	elsif new.cperanio = '2004' then insert into tesoreria.mestcta_a2004 values (new.*);
	elsif new.cperanio = '2005' then insert into tesoreria.mestcta_a2005 values (new.*);
	elsif new.cperanio = '2006' then insert into tesoreria.mestcta_a2006 values (new.*);
	elsif new.cperanio = '2007' then insert into tesoreria.mestcta_a2007 values (new.*);
	elsif new.cperanio = '2008' then insert into tesoreria.mestcta_a2008 values (new.*);
	elsif new.cperanio = '2009' then insert into tesoreria.mestcta_a2009 values (new.*);
	elsif new.cperanio = '2010' then insert into tesoreria.mestcta_a2010 values (new.*);
	elsif new.cperanio = '2011' then insert into tesoreria.mestcta_a2011 values (new.*);
	elsif new.cperanio = '2012' then insert into tesoreria.mestcta_a2012 values (new.*);
	elsif new.cperanio = '2013' then insert into tesoreria.mestcta_a2013 values (new.*);
	elsif new.cperanio = '2014' then insert into tesoreria.mestcta_a2014 values (new.*);
	elsif new.cperanio = '2015' then insert into tesoreria.mestcta_a2015 values (new.*);
	elsif new.cperanio = '2016' then insert into tesoreria.mestcta_a2016 values (new.*);
	elsif new.cperanio = '2017' then insert into tesoreria.mestcta_a2017 values (new.*);
	elsif new.cperanio = '2018' then insert into tesoreria.mestcta_a2018 values (new.*);
	elsif new.cperanio = '2019' then insert into tesoreria.mestcta_a2019 values (new.*);
	elsif new.cperanio = '2020' then insert into tesoreria.mestcta_a2020 values (new.*);
	elsif new.cperanio = '2021' then insert into tesoreria.mestcta_a2021 values (new.*);
	elsif new.cperanio = '2022' then insert into tesoreria.mestcta_a2022 values (new.*);
	elsif new.cperanio = '2023' then insert into tesoreria.mestcta_a2023 values (new.*);
	elsif new.cperanio = '2024' then insert into tesoreria.mestcta_a2024 values (new.*);
	elsif new.cperanio = '2025' then insert into tesoreria.mestcta_a2025 values (new.*);
	else
		raise exception 'Periodo fuera de rango. Es necesario que se comunique con su administrador de base de datos.';
	end if;
	return null;
end;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION tesoreria.mestcta_insert_trigger()
  OWNER TO postgres;
